mui.init() //初始化
mui.plusReady(function() {
	var w = plus.nativeUI.showWaiting("");
	setTimeout(function() {
		plus.nativeUI.closeWaiting();
		//页面信息
		var subInfos = [{
			url: 'view/home.html',
			id: 'home'
		}, {
			url: 'view/zhang.html',
			id: 'contact',
		}, {
			url: 'view/activit.html',
			id: 'email'
		}, {
			url: 'view/my.html',
			id: 'setting'
		}];
		var subStyles = {
			top: '0px',
			bottom: '51px'
		};
		// 根据id查询子页面的信息
		var getSubInfoById = function(infoList, id) {
			var result = null;
			for(var i = 0, len = infoList.length; i < len; i++) {
				var _info = infoList[i];
				if(_info.id === id) {
					result = _info;
					break;
				}
			}
			return result;
		};
		var mainWv = plus.webview.currentWebview();
		var activeTab = '';

		// 默认只加载首页webview
		var homeWv = plus.webview.create(subInfos[0].url, subInfos[0].id, subStyles);
		mainWv.append(homeWv);
		activeTab = subInfos[0].id;
		// 点击切换，动态创建其它webview；
		mui('.mui-bar-tab').on('tap', 'a.mui-tab-item', function(e) {
			var _self = this;
			var targetTab = _self.getAttribute('data-id');
			if(targetTab === activeTab) {
				return;
			}
			var _subWv = plus.webview.getWebviewById(targetTab);
			// 若webview不存在，则创建；
			if(!_subWv) {
				var _subInfo = getSubInfoById(subInfos, targetTab);
				_subWv = plus.webview.create(_subInfo.url, _subInfo.id, subStyles);
				mainWv.append(_subWv);
			}
			_subWv.show();
			// 隐藏之前的webview
			plus.webview.getWebviewById(activeTab).hide('none');
			activeTab = targetTab;
		});
	}, 1500)
});